package com.example.backend.annotation.validation;

import com.example.backend.annotation.constraint.ValidUserId;
import lombok.RequiredArgsConstructor;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 用户ID验证器
 *
 * @author mhwssad
 */
@RequiredArgsConstructor
public class UserIdValidator implements ConstraintValidator<ValidUserId, Integer> {


    @Override
    public void initialize(ValidUserId constraintAnnotation) {
    }

    @Override
    public boolean isValid(Integer userId, ConstraintValidatorContext context) {
        if (userId == null || userId <= 0) {
            return false;
        }

        // 调用数据库查询验证用户是否存在
        return true;
    }
}

